<?php

namespace App\Toor;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;

class Tranks extends Controller
{
    public function go($item)
    {
        return [
            'mage'=>200,
            'mag'=>'成功响应',
            'data'=>$item
        ];
    }

//    生成token
    public function createToken($length = 32)
    {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|";
        $password = "";
        for ( $key = 0; $key < $length; $key++ )
        {
            $password .= $chars[ mt_rand(0, strlen($chars) - 1) ];
        }
        return $password;
    }

//    检查token
    public function CheckToekn($token)
    {
        return Redis::get($token);
    }

//    存储token
    public function getToken($user)
    {
        $token=$this->createToken();
        $userToken=['token'=>$token,'user'=>$user];
        Redis::setex($token,60*60*24,json_encode($userToken));
        return $token;
    }

    public function deToken($retoken)
    {
        return rsps('200',Redis::exists($retoken),'成功响应');
    }

}
